//
//  StudyGroupsHandler.m
//  mUBB
//
//  Created by Cosmin Stirbu on 3/11/13.
//  Copyright (c) 2013 Cosmin Stirbu. All rights reserved.
//

#import "StudyGroupsHandler.h"
#import "StudyGroup.h"
#import "CoursesProtocol.h"

@implementation StudyGroupsHandler

- (void)handleSuccess:(WSResponse *)response {
    NSArray *jsonStudyGroups = [response.data objectFromJSONData];
    NSMutableArray *studyGroups = [NSMutableArray new];
    for (NSDictionary *studyGroupJson in jsonStudyGroups) {
        StudyGroup *studyGroup = [StudyGroup new];
        studyGroup.studyGroupId = [[studyGroupJson getJSONObjectForKey:STUDY_GROUP_ID_TAG] integerValue];
        studyGroup.name = [studyGroupJson getJSONObjectForKey:STUDY_GROUP_NAME_TAG];
        [studyGroups addObject:studyGroup];
    }
    [self.delegate didReceiveStudyGroupsWithSuccess:studyGroups forTicket:self.ticket];
}

- (void)handleError:(WSError *)error {
    [self.delegate didReceiveStudyGroupsWithFailure:error forTicket:self.ticket];
}

@end
